﻿@page "/sdk/server/job/l/list"
@using Newtonsoft.Json;

@model WebVella.Erp.Plugins.SDK.Pages.Job.ListModel
@{
	Layout = "~/Pages/_AppMaster.cshtml";
	ViewData["Title"] = "Logs";
}

<wv-page-header color="#dc3545" area-label="Jobs" title="Background Jobs"
				icon-class="fa fa-cog icon" return-url="@Model.ReturnUrl">
	<wv-page-header-actions>
		<wv-button type="Button" onclick="ErpEvent.DISPATCH('WebVella.Erp.Web.Components.PcDrawer','open')" color="White" icon-class="fa fa-search" text="Search jobs" size="Small"></wv-button>
	</wv-page-header-actions>
	<wv-page-header-toolbar>
		@foreach (var action in Model.HeaderToolbar)
		{
			@Html.Raw(action)
		}
	</wv-page-header-toolbar>
</wv-page-header>

<wv-grid bordered="true" hover="true" columns="Model.Columns" page="Model.Pager" total-count="Model.TotalCount" page-size="Model.PagerSize" vertical-align="Middle">
	@foreach (var record in Model.Records)
	{
		<wv-grid-row>
			<wv-grid-column>
				<wv-button type="Button" onclick="$('#wv-@record.Id').modal('show')" color="White" size="Small" icon-class="fa fa-eye fa-fw"></wv-button>
				<wv-modal size="ExtraLarge" title="System Log Details" id="wv-@record.Id">
					<wv-modal-body>
						<wv-field-code height="300px" label-mode="Hidden" name="json" value="@(JsonConvert.SerializeObject(record, Formatting.Indented))" language="json"></wv-field-code>
					</wv-modal-body>
					<wv-modal-footer>
						<wv-button type="Button" onclick="$('#wv-@record.Id').modal('hide')" color="White" size="Small" text="Close"></wv-button>
					</wv-modal-footer>
				</wv-modal>
			</wv-grid-column>
			<wv-grid-column>
				<wv-field-datetime label-mode="Hidden" mode="Simple" value="@(record.CreatedOn.ConvertToAppDate())"></wv-field-datetime>
			</wv-grid-column>
			<wv-grid-column>
				<wv-field-datetime label-mode="Hidden" mode="Simple" value="@(record.StartedOn.ConvertToAppDate())"></wv-field-datetime>
			</wv-grid-column>
			<wv-grid-column>
				<wv-field-datetime label-mode="Hidden" mode="Simple" value="@(record.FinishedOn.ConvertToAppDate())"></wv-field-datetime>
			</wv-grid-column>
			<wv-grid-column>
				@record.TypeName
			</wv-grid-column>
			<wv-grid-column>
				@record.CompleteClassName
			</wv-grid-column>
			<wv-grid-column horizontal-align="Center">
				<span title="@record.Status.ToString()">@record.Status.ToString()</span>
			</wv-grid-column>
		</wv-grid-row>
	}
	@if (Model.Records.Count == 0)
	{
		<tbody>
			<tr>
				<td colspan="@Model.Columns.Count"><div class="alert alert-info">No jobs found</div></td>
			</tr>
		</tbody>
	}
</wv-grid>

@{ 
var titleAction = "<a href=\"javascript:void(0)\" class=\"clear-filter-all\">clear all</a>";
}
<wv-drawer id="logSearchDrawler" width="400px" title="Search jobs" title-action-html="@titleAction">
	<form method="get" name="Search">
		<wv-filter-text label="Type Name" name="type_name" query-type="CONTAINS" query-options="@(new List<FilterType> { FilterType.CONTAINS })"></wv-filter-text>
		<wv-filter-text label="Type Id" name="type_id" query-type="EQ" query-options="@(new List<FilterType> { FilterType.EQ })"></wv-filter-text>
		<hr class="divider" />
		<wv-button type="Submit" color="White" text="Search logs" size="Small"></wv-button>
	</form>
</wv-drawer>